//
// Created by v on 19-6-10.
//

#include <list>

#include "funcs/CMObserver.h"
#include "utils/cm_logprint.h"

CMLogPrint logPrint;

class ObserverMain : public CMObserver
{
  public:
    void notifyAll(int x);
};

void ObserverMain::notifyAll(int x) { updateAll(&x); }

class ObserverListen : public CMObserver
{
    int statusChanged(void *args);
};

int ObserverListen::statusChanged(void *args)
{
    int i = *(int *)args;
    cminfo("status changed with [%d]\n", i);
    return 0;
}

int main(int argc, char **args)
{
    CM_LOG_PRINT_INIT("cm_observer");
    cminfo("start of main\n");
    ObserverMain *  om = new ObserverMain();
    ObserverListen *ol = new ObserverListen();
    om->registerObserver(ol);
    ObserverListen *ol1 = new ObserverListen();
    om->registerObserver(ol1);

    ObserverListen *ol2 = new ObserverListen();
    om->registerObserver(ol2);

    cminfo("start to notify\n");
    om->notifyAll(8);

    om->unregisterObserver(ol1);
    cminfo("start to notify\n");
    om->notifyAll(24);

    getchar();
    return 0;
}
